<template>
  <div class="tab-container">
    <el-tabs v-model="activeName" style="margin-top:15px;" type="border-card">
      <el-tab-pane v-for="item in tabMapOptions" :key="item.key" :label="item.label" :name="item.key">
        <keep-alive>
          <tab-pane v-if="activeName==item.key" :type="item.key" :list="list"@create="showCreatedTimes" />
        </keep-alive>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import TabPane from './components/TabPane'


export default {
  name: 'Tab',
  components: { TabPane },
  data() {
    return {
      tabMapOptions: [
      { label: 'USA', key: 'US' },
      ],
      activeName: 'US',
      createdTimes: 0,
      taskArray: [],
      list: [],
      uid: '',
      tid: '',
      uid_modify: '',
      tid_modify: '',
      tid_finish: ''
    }
  },
  watch: {
    activeName(val) {
      this.$router.push(`${this.$route.path}?tab=${val}`)
    }
  },
  created() {
  },
  mounted() {
    var myHeaders = new Headers();
    myHeaders.append("User-Agent", "Apifox/1.0.0 (https://apifox.com)");
    myHeaders.append('Authorization', 'Bearer ' + sessionStorage.getItem('token'))

    var requestOptions = {
      method: 'POST',
      headers: myHeaders,
      redirect: 'follow'
    };

    fetch("http://1.92.204.101:5000/task/get_my_tasks", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));
  },
  created() {
    // init the default selected tab
    const tab = this.$route.query.tab
    if (tab) {
      this.activeName = tab
    }
  },
  methods: {
    showCreatedTimes() {
      this.createdTimes = this.createdTimes + 1
    },
  }
}
</script>

<style scoped>
  .tab-container {
    margin: 30px;
  }
</style>
